package org.zfes.snowier.cloud.zbss.pmp.router.service.pm;

import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.util.ZDateUtil;
import org.zfes.snowier.core.util.datex.ZDateStyle;
import org.zfes.snowier.web.controller.BaseController;



import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpTasksCreateDto;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpTasksSplitDto;

import org.zfes.snowier.cloud.zbss.pmp.model.PmpTasks;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpTasksService;

@Controller("org.zfes.snowier.cloud.zbss.pmp.router.service.pm.pmpTasksController")
@RequestMapping("/pmp/service/pm/pmpTasks")
public class PmpTasksController extends BaseController {

	
	@Autowired
	private IPmpTasksService pmpTasksService;

   
    @RequestMapping(value="/loadPmpTasksDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadPmpTasksDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  pmpTasksService.loadPmpTasksDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }

    
    @RequestMapping(value="/createPmpTasks", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createPmpTasks( PmpTasksCreateDto tasksCreateDto){
		pmpTasksService.createPmpTasks(SecurityUtil.getUserId().get(),tasksCreateDto);
    	return ajaxDoneSuccess("数据操作成功 ");
    }

   //项目经理加载自己负责的项目中的任务列表
    @RequestMapping(value="/loadPmpTasksByProjectId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadPmpTasksByProjectId(Long projectId){
		List<PmpTasks> pmpTasksList= pmpTasksService.loadPmpTasksByProjectId(projectId);
		return ajaxQuery("pmpTasksList",pmpTasksList);
    }

   //更新进一步拆分
    @RequestMapping(value="/updateExpired", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateExpired(Long id,Byte expired){
		pmpTasksService.updateExpired(id, expired);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/updateAssignHours", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateAssignHours(Long id,Integer assignHours){
		pmpTasksService.updateAssignHours(id, assignHours);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    @RequestMapping(value="/updateWorkHours", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateWorkHours(Long id,Integer workHours){
		pmpTasksService.updateWorkHours(id, workHours);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/updateTaskName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateTaskName(Long id,String taskName){
		pmpTasksService.updateTaskName(id, taskName);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/updateExpiryTime", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateExpiryTime(Long id,String expiryTime ){
		pmpTasksService.updateExpiryTime(id, ZDateUtil.parseDate(expiryTime, ZDateStyle.YYYY_MM_DD_HH_MM_SS));
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/updateDifficultyScore", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateDifficultyScore(Long id, Long  difficultyScoreId){
		pmpTasksService.updateDifficultyScore(id, difficultyScoreId);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    @RequestMapping(value="/updateVersion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateVersion(Long id, Long  versionId){
		pmpTasksService.updateVersion(id, versionId);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/asignPmpTasks", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object asignPmpTasks(Long id, Long  chargeUserId){
		pmpTasksService.setPmpTasksChargeUser(id, chargeUserId);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/setPmpTasksStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object setPmpTasksStatus(Long id,Byte status){
		pmpTasksService.setPmpTasksStatus(id, status);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
    @RequestMapping(value="/checkTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object checkTask(Long id,Byte isOk,String rejectResaon){
		pmpTasksService.checkTask(id, isOk,rejectResaon);
		return ajaxDoneSuccess("数据操作成功 ");
    }

    @RequestMapping(value="/addOnesplitPmpTasks", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object addOnesplitPmpTasks(Long taskId,PmpTasksSplitDto splitDto){
		pmpTasksService.addOnesplitPmpTasks(SecurityUtil.getUserId().get(),taskId, splitDto);
		return ajaxDoneSuccess("数据操作成功 ");
    }
}